package com.pengliu.util;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.pengliu.service.HttpService;
import com.pengliu.service.impl.HttpServiceImpl;

public class IpUtil {
	

	/**
	 * user: pengliu
	 * date: 2017年9月29日
	 * desc: 获取真实IP地址
	 * @return
	 * @throws Exception
	 */
	public static String getIpAddress() throws Exception {
		
		String url = "http://ip.taobao.com/service/getIpInfo2.php?ip=myip";
		
		HttpService httpService = new HttpServiceImpl();
		
		String resultJson = httpService.requestGet(url);
		
		String data = JSON.parseObject(resultJson, Map.class).get("data").toString();
		String ip = JSON.parseObject(data, Map.class).get("ip").toString();
		return ip;
	}
	
	public static void main(String[] args) throws Exception {
		System.out.println(IpUtil.getIpAddress());
	}
	
}
